package com.mm.seguridad.service;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class MMAuthenticationToken extends AbstractAuthenticationToken {
    private final Object principal;
    private Object token;
    private Object credentials;
    private Object usuarioId;
    private Object grupoEmpresarialId;
    private Object rolId;

    //~ Constructors ===================================================================================================


    public MMAuthenticationToken(Object principal, Object credentials, Object usuarioId, Object grupoEmpresarialId, Object rolId,Collection<? extends GrantedAuthority> authorities ) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.usuarioId = usuarioId;
        this.grupoEmpresarialId = grupoEmpresarialId;
        this.rolId = rolId;
        super.setAuthenticated(true); // must use super, as we override
    }

    public MMAuthenticationToken(Object principal, Object credentials,Object token, Object usuarioId, Object grupoEmpresarialId, Object rolId,Collection<? extends GrantedAuthority> authorities ) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.token= token;
        this.usuarioId = usuarioId;
        this.grupoEmpresarialId = grupoEmpresarialId;
        this.rolId = rolId;
        super.setAuthenticated(true); // must use super, as we override
    }

    public MMAuthenticationToken(Object principal, Object credentials) {
        super(null);
        this.principal = principal;
        this.credentials = credentials;
         setAuthenticated(false);
    }


     public MMAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true); // must use super, as we override
    }

     public MMAuthenticationToken(Object principal, Object credentials,Object token, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.token= token;
        this.credentials = credentials;
        super.setAuthenticated(true); // must use super, as we override
    }




    //~ Methods ========================================================================================================

    public Object getCredentials() {
        return this.credentials;
    }

    public Object getPrincipal() {
        return this.principal;
    }



    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (isAuthenticated) {
            throw new IllegalArgumentException(
                    "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
        }

        super.setAuthenticated(false);
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        credentials = null;
    }

    public Object getUsuarioId() {
        return usuarioId;
    }

    public void setUsuarioId(Object usuarioId) {
        this.usuarioId = usuarioId;
    }

    public Object getGrupoEmpresarialId() {
        return grupoEmpresarialId;
    }

    public void setGrupoEmpresarialId(Object grupoEmpresarialId) {
        this.grupoEmpresarialId = grupoEmpresarialId;
    }

    public Object getRolId() {
        return rolId;
    }

    public void setRolId(Object rolId) {
        this.rolId = rolId;
    }

    public Object getToken() {
        return token;
    }

    public void setToken(Object token) {
        this.token = token;
    }
}
